package com.xf.service.feign;

import com.xf.common.core.domain.DmpResult;
import com.xf.common.core.entity.dmp.DmpAuthUser;
import com.xf.common.core.feign.UserFeignConfig;
import com.xf.mapper.DmpAuthUserMapper;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author JoeyLiu
 * @create 2022-03-31 16:23
 */
@RestController
public class UserFeignConfigImpl implements UserFeignConfig {
    @Resource
    private DmpAuthUserMapper dmpUserMapper;

    @Override
    public DmpResult<List<DmpAuthUser>> getByUserName(DmpAuthUser user) {
        return DmpResult.data(dmpUserMapper.getOneByName(user));
    }

    @Override
    public DmpResult<List<DmpAuthUser>> getByIds(List<String> ids) {
//        return DmpResult.data(dmpUserMapper.getByIds(ids));
        return DmpResult.success();
    }

    @Override
    public DmpResult<DmpAuthUser> getById(Long id) {
//        .data(dmpUserMapper.selectByPrimaryKey(id))
        return DmpResult.success();
    }

    @Override
    public DmpResult addUser(DmpAuthUser user) {
        DmpAuthUser userInfo = dmpUserMapper.getOneByName(user);
        if (Objects.nonNull(userInfo)) {
            return DmpResult.failed("该账号已被使用");
        }
        dmpUserMapper.insert(user);
        return DmpResult.success();
    }

    @Override
    public DmpResult updataUser(DmpAuthUser user) {
        dmpUserMapper.updateById(user);
        return DmpResult.success();
    }


}
